<div class="top">
	<div class="tl">
        <a href="#default/main">
		{{bus_info.info.title}}
        </a>
	</div>
	<div class="tr">
		{{#if loginer}}
		<a class="{{$Cache.is_collect_current_bus&&'icon-star3'||'icon-star'}}" event-click="{{'$Event.user_collect_bus'}}"></a>
        <!-- <a class="icon-cart" href="#default/cart"></a>
        <a href="mobile.personal.html" class="icon-user"></a> -->
		{{#else}}
		<!-- <a href="#default/sign" class="icon-user2"></a> -->
		{{/if}}
	</div>
</div>
{{#if $Cache.bus.assshop.list.length}}
<div class="assshopbox {{$Assshop_jump&&'focus'}}">
    <div class="item1">请选择</div>
    <div 
    class="item2" event-click="{{'$Event.check_assshop'}}">立即点餐</div>
    <div class="item1">或者转到店铺</div>
    {{#each $Cache.bus.assshop.list}}
    <a href="{{bus.url}}">
        <div class="item2">{{bus.info.title}}</div>
    </a>
    {{/each}}
</div>
{{/if}}

<div class="bottom">
	<a href="#default/main">首页</a>
	<a href="#default/goodslist?id=3">商品</a>
	<!-- <a href="#default/tags">分类</a> -->
	<a href="#default/storeinfo">简介</a>
    <!-- <a href="#default/help">攻略</a> -->
    <a href="#default/cart">购物车</a>
	<a href="{{#if loginer}}mobile.personal.html{{#else}}#default/sign{{/if}}">{{#if loginer}}我的{{#else}}登陆{{/if}}</a>
</div>
<link rel="stylesheet" type="text/css" href="/css/catering/mobile_top.css" />

<script type="text/vm">
    function (vm) {
        require(["common","coAjax","href","eventManager","hash_routie","windowScroll","routie"], function(jSouper,coAjax,href,eventManager,hash_routie,windowScroll,routie) {
            // 获取back_url
            get_back_url();
            window.addEventListener("hashchange",get_back_url);
            function get_back_url(){
                if (location.hash.indexOf("#default/sign")==-1) {
                    App.set("$Cache.cb_url",location.href);
                } else {
                    App.set("$Cache._in_sign_in_or_up", true);
                }
            }
            function _check_collect_bus (collectBus) {
                var is_collect = true;
                if (jSouper.indexOf(collectBus,appConfig.bus_id)===-1) {
                    is_collect = false;
                }
                App.set("$Cache.is_collect_current_bus",is_collect)
            };
            eventManager.on("getLoginer",function () {
                //校验是否已经收藏过此商家
                var collectBus = App.get("loginer.collectBus")||[];
                _check_collect_bus(collectBus);
            });
            
            ;(window.coAjaxLoginUser = function(succ_cb){
                // alert("获取登陆者信息……"+location.pathname)
        
                //获取登陆用户的信息
                /*
                 * 管理员相关的页面无需登录
                 */
                var no_user_login_pages = {
                    "http://admin.dotnar.com": 1,
                    "http://admin.dotnar.com": 1
                }
                if (no_user_login_pages[location.pathname]) {
                    return;
                }
                // alert("开始获取"+appConfig.user.loginer)
                console.log("获取登陆者信息……", location.pathname);
                /*
                 * 获取登录者信息
                 */
                coAjax.get(appConfig.user.loginer,{
                    _:Math.random()
                }, function(data) {
                    // alert("success","用户登录成功");
                    console.log("登录者信息：", data.result);
                    userInfo = data.result;
                    App.set("loginer", userInfo);
                    //触发相关事件
                    eventManager.fire("getLoginer");
                    succ_cb&&succ_cb();
                }, function(errorCode) {
                    // alert("用户未登录");
                    var muse_login_pages = {
                        "#default/sign": 1,
                        "#default/cart": 1
                    };
                    //未登录，不可进入个人页，强制跳转到登录页
                    if (muse_login_pages[location.pathname]) {
                        href.toLogin();
                    }
                });
            })();
            

            App.set("$Event.user_collect_bus",function () {
                if(!App.get("loginer")){
                    myConfirm("请先登陆！！！",function(){
                        location.href="catering.mobile.html#default/sign";
                    });
                    return
                };
                if (App.get("$Cache.is_collect_current_bus")) {
                    coAjax["delete"](appConfig.user.collectBus_remove,{
                        bus_id:appConfig.bus_id
                    },function (result) {
                        alert("已取消店铺收藏");
                        // App.set('$Cache.is_collect_current_bus',false);
                        _check_collect_bus(result.result);
                    },function (errorCode,xhr,errorMsg) {
                        // alert("error",errorMsg)
                        _check_collect_bus(App.get("loginer.collectBus"));
                    });
                }else{
                    coAjax.post(appConfig.user.collectBus_add,{
                        bus_id:appConfig.bus_id
                    },function (result) {
                        alert("success","店铺收藏成功");
                        // App.set('$Cache.is_collect_current_bus',true);
                        _check_collect_bus(result.result);
                    },function (errorCode,xhr,errorMsg) {
                        // alert("error",errorMsg)
                        _check_collect_bus(App.get("loginer.collectBus"));
                    });
                }
            });

            
            App.set('$Event.block_close',function(){
                clearInterval(t);
                App.set('TopPrivate',false);
            });
            
            //判断是否为购买服务
            App.set("$Event.check_assshop",function(){
                App.set("$Assshop_jump",true);
            });
        });
    }
</script>
